package test9;

import java.util.HashMap;
import java.util.Scanner;
import java.util.Stack;

public class Demo4 {

    static Stack<Integer> number = new Stack<>();
    static Stack<Character> option = new Stack<>();
    static HashMap<Character, Integer> priority = new HashMap<>();

    public static void main(String[] args) {
        priority.put('+', 1);
        priority.put('-', 1);
        priority.put('^', 2);

        //int a = 3 + (5 ^ 2) - 9;
        Scanner sc = new Scanner(System.in);
        String s = sc.next();


        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == '+' || c == '-' || c == '^') {
                if (!option.isEmpty()) {
                    Character peek = option.peek();
                    if (priority.get(c) <= priority.get(peek)) {
                        dispose(option.pop());
                    }
                }
                option.add(c);
            } else {
                number.add(Integer.parseInt(String.valueOf(c)));
            }
        }

        while (!option.isEmpty()) {
            dispose(option.pop());
        }

        System.out.println(number.pop());
    }


    public static void dispose(Character c) {
        Integer pop1 = number.pop();
        Integer pop2 = number.pop();
        if (c == '+') {
            number.add(pop2 + pop1);
        } else if (c == '-') {
            number.add(pop2 - pop1);
        } else {
            number.add(pop2 ^ pop1);
        }
    }
}

